Q: How do I call a callback function and have it execute a particular subroutine.
When you select Window ToFunction in the toolkit, GuiDesigner converts the currently displayed design window into a pair of functions, a "grid function" and a "callback function".  When your program is running and something important happens in the window, the grid function calls XuiCallback() , which in turn calls the callback function with a #Callback message, and the real message in r1 .   Usually the original message is #Selection .

But your programs can call callback functions too.  You can arrange arguments to simulate a callback, or you can arrange the arguments in any other way you wish.   Near the top of most callback functions, you'll find something like the following:

FUNCTION TestCode (grid, message, v0, v1, v2, v3, kid, r1)
  $MenuBar = 1    ' kid #1
  $TextLine = 2   ' kid #2
  $Button = 3     ' kid #3
  $Custom = 100   ' custom kid #
'
  IF (message = #Callback) THEN
    callback = r1
    message = r1
  END IF
'
  SELECT CASE message
    CASE #Selection  : GOSUB Selection  ' normal #Selection message
    CASE #Custom     : GOSUB Custom      ' or custom code right here
  END SELECT
  RETURN
'
SUB Selection
  SELECT CASE kid
    CASE $MenuBar  : ' code to handle MenuBar selections
    CASE $TextLine : ' code to handle TextLine selections
    CASE $Button   : ' code to handle Button0 selections
    CASE $Custom   : ' code to handle custom capability
  END SELECT
END SUB

The following three lines were added to the GuiDesigner generated code to prepare the callback function for special purpose messages from your program:

 $Custom = 100 ' custom kid #
 CASE #Custom : GOSUB Custom ' or custom code right here
 CASE $Custom : ' code to handle custom capability

To invoke the CASE #Custom : GOSUB Custom line, your program calls:
  TestCode (grid, #Custom, v0, v1, v2, v3, kid, r1)

To invoke the CASE $Custom line, your program calls:
TestCode (grid, #Selection, v0, v1, v2, v3, $Custom, r1)

Sample applications acircle.x and ademo.x contain an example.  Also make sure you XgrRegisterMessage (@"Custom", @#Custom) in InitProgram().